package com.kfm.am.generic;

import com.kfm.am.Movie;
import com.kfm.am.Student;

import java.util.ArrayList;
import java.util.Comparator;

public class GenericTest {

    public static void main(String[] args) {

        ArrayList<Sub> arrayList = new ArrayList<>();
        // Comparator<? super E> Sub Super Object

        Comparator<Super> comparator = new Comparator<Super>() {
            @Override
            public int compare(Super o1, Super o2) {
                return 0;
            }
        };
        Comparator<Sub> subComparator = new Comparator<Sub>() {
            @Override
            public int compare(Sub o1, Sub o2) {
                return 0;
            }
        };

        Comparator c = new Comparator() {
            @Override
            public int compare(Object o1, Object o2) {
                return 0;
            }
        };

        arrayList.sort(comparator);
        arrayList.sort(subComparator);
        arrayList.sort(c);
    }

}

class StuGeneric implements Generic<Student> {

    @Override
    public void test(Student student) {

    }


}

class Test {

    // ? 代表 Generic 泛型类型可以是 Super及子类
    public void test(Generic<? extends SuperFather> g) {

    }
    // ？ 代表 Generic 泛型类型是任意类型
    public void test01(Generic<?> g) {

    }

    public <E> void test04(Generic<E> g) {

    }

    // ？ 代表Generic 泛型类型可以是 Sub及所有父类
    public void test03(Generic<? super Sub> g) {

    }

    public void test02() {
        test(new Generic<Sub>() {
            @Override
            public void test(Sub sub) {

            }
        });
        //
        test03(new Generic<SuperFather>() {
            @Override
            public void test(SuperFather sub) {

            }
        });
        test01(new Generic<Sub>() {
            @Override
            public void test(Sub sub) {

            }
        });

        test01(new Generic<Movie>() {
            @Override
            public void test(Movie sub) {

            }
        });

        test04(new Generic<Movie>() {
            @Override
            public void test(Movie sub) {

            }
        });

    }

}


interface Generic<T> {

    void test(T t);
}
